package com.wws.family.adapter

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.ViewGroup
import com.wika.basics.base.BaseBindViewHolder
import com.wika.basics.base.BaseRecyclerViewAdapter
import com.wws.family.R
import com.wws.family.databinding.ItemRecentBinding
import com.wws.family.db.MedicineBean
import com.wws.family.ui.activity.MedicineAddActivity
import com.wws.family.utils.DateUtils

/**
 *@Description:近期动态
 *@Date: 2025/1/7 22:28
 *@Author: WangWeiShuo
 */
class RecentAdapter(val context: Context):BaseRecyclerViewAdapter<MedicineBean,ItemRecentBinding>() {
    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<ItemRecentBinding>,
        item: MedicineBean?,
        position: Int
    ) {
        holder.binding.tvRecentName.text = item?.name
        holder.binding.tvRecentTime.text = item?.endTime
        val endDate = item?.endDate
        if(endDate.equals(DateUtils.getNowDateNoHeng())){
            holder.binding.tvRecentStatus.text = "今日到期"
            holder.binding.tvRecentStatus.setTextColor(context.getColor(R.color.green_00C853))
        }else{
            holder.binding.tvRecentStatus.text = "已过期"
            holder.binding.tvRecentStatus.setTextColor(context.getColor(R.color.red_DD2C00))
        }
        holder.itemView.setOnClickListener {
            val intent = Intent(context, MedicineAddActivity::class.java)
            intent.putExtra("medicineItem",item)
            context.startActivity(intent)
        }
    }

    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ItemRecentBinding {
        return ItemRecentBinding.inflate(layoutInflater,parent,false)
    }
}